package com.sc.everyonerentboot.controller;

import com.sc.everyonerentboot.pojo.Products;
import com.sc.everyonerentboot.pojo.Result;
import com.sc.everyonerentboot.service.BrowseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BrowseController {
    @Autowired
    private BrowseService bs;

    @RequestMapping("/showHistory")
    public Result showHistory(Integer userId) {
        if (userId == null){
            return new Result(0,"用户未登录",null);
        }
        List<Products> products = bs.showHistory(userId);
        if (products == null){
            return new Result(0,"无数据",null);
        }
        return new Result(1,"查询成功",products);
    }

    @RequestMapping("/delBroHistory")
    public Result delBroHistory(Integer userId,Integer[] pids) {
        int i = bs.delBroHistory(userId, pids);
        if (i == 0){
            return new Result(0,"删除失败");
        }
        return new Result(1,"删除成功",i);
    }

    @RequestMapping("/addBroHistory")
    public Result addBroHistory(Integer userId,Integer pid) {
        int i = bs.addBroHistory(userId, pid);
        if (i == 0){
            return new Result(0,"记录已存在");
        }
        return new Result(1,"添加成功",i);
    }
}
